Repository navigation
Report an error in a loop body only with invariants proved on every path - #555
CatarinaGamboa wants to merge 2 commits into
Conversation
An error that stops the check of a loop body leaves the candidate invariants unchecked on the paths after it, and the error showed them as facts. The statement where the check stopped is now skipped in the next checks, as if it changed anything it may change, until the candidates reach a fixpoint; the body is then checked again to report the error. A statement that cannot be skipped drops all candidates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex review, round 1No soundness or correctness finding. Codex ran five programs against this branch and main. None reported an error from an unproved invariant, accepted a wrong program, hung or crashed:
Code quality
What was done
Nothing to push for this round. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex review, round 2No problem found. Codex wrote 15 programs (in the scratchpad, not in the repo). None of them verified while it broke a refinement, and no reported loop-head fact was false on an iteration that goes on. The skipped statement contained, in turn:
Codex also tried a There are no findings in two rounds, so the Codex loop for this PR ends here. |
Clean-code reviewI audited only this PR's new code (
|
Fixes #553
Part of the loop invariant inference plan (#542). Independent of #552 (based on main).
What and why
When an error stopped the check of a loop body before a back edge, the candidate invariants assumed at the head were never checked on the paths after it, so they were never dropped, and the reported error showed them as facts (#553:
found total@18#1 >= 0 && total@18#1 <= 0 && ...).The issue suggested dropping the candidates not proved at a back edge reached, or all of them if none was reached. I tried that first, and it is sound, but it moves errors onto lines that are correct: in
the error at
small(i)stops every check, so all candidates are dropped, and the error is then reported atuse(i)asfound i < 10 but expected i >= 0. That is the #537 false alarm again, in any loop that has another error, which is what study participants will write.So this PR keeps checking the rest of the body instead:
checkUntilFixpointcatches it), the top-level statement of the body where it stopped (recorded by ascanoverride) is skipped in the next checks: the checker forgets what it may change (changedIn, as for the loop itself) and declares the variable it declares, if any.reporting), and that check reports the error, with candidates proved on every path.Soundness argument
continueto this loop or an outer loop cannot be skipped. Abreak,returnorthrowit hides only adds paths to check.Before / after (main → this PR)
found total@16#1 >= 0 && total@16#1 <= 0 && total@16#1 <= 100 && ...found total@16#1 < 100 && total == total@16#1 + #read_resultfor (i = 0; i < 10; i++) { use(i); small(i); }small(i),found i < 10 && i >= 0 && i <= 10use(i))for (i...) { small(i); k = k - 1; use(k); }use(k),found k@8 >= 0 && k@8 <= 0 && ....small(i)passed only because of the falsei <= 0small(i),found i < 10 && i >= 0 && i <= 10while (i < 10) { if (c()) { bad(i); i = -1; } i++; }found i < 10 && i >= 0 && i <= 0 && i <= 10found i < 10int x = bad(i);in afor(declaration skipped)... i >= 0 && i <= 0 ...found i < 10 && i >= 0 && i <= 10i = i - 5; continue;(cannot be skipped)... i >= 0 && i <= 0 ...found i < 10Tests
ErrorLoopUnprovedInvariant(new fixture, one method): an accumulator with an error afternonNeg(i).TestCounterexamples.errorInLoopBodyShowsNoUnprovedInvariant: Found has no<= 0. Fails on main (#total_2 >= 0 && #total_2 <= 0 && ...).Expectline also fails with the suggested "drop all" fix, which reportsnonNeg(i)(line 17).Full suite passes locally. Study tasks (
verify-tasks.py, 55 variants): verdicts and messages identical toverify-cur-redesign.json.Timing
Correct programs do the same work as before. A loop whose body has an error now costs one more body check per skipped statement, plus the report check. Same machine (shared, load ~5 on 4 cores, so noisy):
mvn -q testwallErrorLoopInvariantsErrorLoopConditionErrorLoopStateFixpointCorrectLoopInvariantsCorrectLoopStateFixpointverify-tasks.py, wall)🤖 Generated with Claude Code